﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Option.aspx.cs" Inherits="MsgCenter.Web.Pages.DeptManage.Option"
    MasterPageFile="~/Option.Master" %>

<asp:Content ContentPlaceHolderID="headContent" runat="server">
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/myJqgrid.js") %>"></script>
    <script type="text/javascript">
        var deptName_ID = "<%=txtDeptName.ClientID %>";
        //******************************** 校验必填项 ********************************
        function CheckSubmit() {
            var CheckResult = CheckValue();
            if (CheckResult == 'success') {
                return true;
            }
            else {
                showDialogMessage(CheckResult);
                return false;
            }
        }
        function CheckValue() {
            if ($('#' + deptName_ID).val() == "") {
                $('#' + deptName_ID).focus();
                return "部门名称必须填写！";
            }
            return "success";
        }
        //******************************** 校验必填项 ********************************
        //******************************** 提示信息 ********************************
        function AlertMessage(message) { alert(message); }
        function Close_Reload() {
            window.parent.CBClose_Load();
        }
        //******************************** 提示信息 ********************************
    </script>
</asp:Content>
<asp:Content runat="server" ContentPlaceHolderID="mailContent">
    <asp:Panel ID="pnlOption" runat="server" Visible="false">
        <table width="660px" cellpadding="0" cellspacing="0">
            <tr>
                <td width="80px" align="right" height="35px">
                    部门代码:
                </td>
                <td width="240px" align="left">
                    <input type="text" id="txtDeptCode" runat="server" placeholder="" class="form-control col-xs-10 col-sm-5"
                        style="width: 200px" />
                </td>
                <td width="80px" align="right" height="35px">
                    <font color="red">*</font>&nbsp;部门名称:
                </td>
                <td width="240px" align="left">
                    <input type="text" id="txtDeptName" runat="server" placeholder="" class="form-control col-xs-10 col-sm-5"
                        style="width: 200px" />
                </td>
            </tr>
        </table>
    </asp:Panel>
    <asp:Panel ID="pnlSort" runat="server" Visible="false" Width="100%">
        <table width="660px" cellpadding="0" cellspacing="0">
            <tr>
                <td align="right" style="width: 50%">
                    <asp:ListBox ID="lstBox" runat="server" Width="220px" Height="300px"></asp:ListBox>
                </td>
                <td align="left" style="width: 50%">
                    <a href="#" class="btn btn-app btn-purple btn-xs" onclick="javascript:moveUpDown('up','<%=lstBox.ClientID %>');">
                        <i class="icon-cloud-upload bigger-160"></i>向上移</a> <a href="#" class="btn btn-app btn-purple btn-xs"
                            onclick="javascript:moveUpDown('down','<%=lstBox.ClientID %>');"><i class="icon-cloud-download bigger-160">
                            </i>向下移</a>
                </td>
            </tr>
        </table>
        <script type="text/javascript" language="javascript">
            //移动select中选项
            function moveUpDown(aim, obj) {
                var Obj = document.getElementById(obj);
                if (aim == "up")//如果向上移动;
                {
                    if (Obj.length - Obj.selectedIndex == Obj.length) {
                        alert("已经是排第一了,无法再进行上移");
                        return;
                    }
                    else if (Obj.selectedIndex != -1) {
                        oldSelected = Obj.selectedIndex;
                        oldText = Obj.options[Obj.selectedIndex].text;
                        oldValue = Obj.options[Obj.selectedIndex].value;
                        Obj.options[Obj.selectedIndex] = new Option(Obj.options[Obj.selectedIndex - 1].text, Obj.options[Obj.selectedIndex - 1].value)
                        Obj.options[oldSelected - 1] = new Option(oldText, oldValue);
                        Obj.options[oldSelected - 1].selected = true;
                    }
                    else {
                        alert("请先选择需要移动项"); return;
                    }
                }
                else if (aim == "down")//向下移动;
                {
                    if (Obj.selectedIndex == -1) {
                        alert("请先选择需要移动项"); return;
                    }
                    else if (Obj.length - Obj.selectedIndex == 1) {
                        alert("已经是最后,无法再进行下移");
                        return;
                    }
                    else {
                        current_ = Obj.selectedIndex;
                        current_text = Obj.options[Obj.selectedIndex].text;
                        current_value = Obj.options[Obj.selectedIndex].value;
                        Obj.options[Obj.selectedIndex] = new Option(Obj.options[Obj.selectedIndex + 1].text, Obj.options[Obj.selectedIndex + 1].value);
                        Obj.options[current_ + 1].text = current_text;
                        Obj.options[current_ + 1].value = current_value;
                        Obj.options[current_ + 1].selected = true;
                    }
                }
                getValues(Obj);
            }

            //将选择的值放入隐藏控件 
            function getValues(ObjTo) {
                var ObjHid = document.getElementById("<%=hidValue.ClientID %>");
                ObjHid.value = "";
                var m = ObjTo.options.length;
                for (var i = 0; i < m; i++) {
                    ObjHid.value += ObjTo.options[i].value + ",";
                }
                ObjHid.value = ObjHid.value.substring(0, ObjHid.value.lastIndexOf(","));
            } 
        </script>
        <asp:HiddenField ID="hidValue" runat="server" />
    </asp:Panel>
    <br />
    <div style="text-align: center">
        <asp:LinkButton ID="linkSave" runat="server" CssClass="btn btn-info" OnClick="linkSave_Click"
            OnClientClick="return CheckSubmit();"><i class="icon-ok bigger-110"></i>保存</asp:LinkButton>
        &nbsp;&nbsp;
        <button class="btn" onclick="window.parent.CBClose();return false;">
            <i class="icon-undo bigger-110"></i>取消
        </button>
    </div>
</asp:Content>
